home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
- From: grantp@usa.pipeline.com(Pete Grant)
- Newsgroups: comp.lang.c++
- Subject: Re: Newbie Ques: Templates and C++
- Date: 23 Mar 1996 21:58:09 GMT
- Organization: Pipeline USA
- Message-ID: <4j1s5h$am8@news1.h1.usa.pipeline.com>
- References: <DoqLy6.H7q@novice.uwaterloo.ca>
- NNTP-Posting-Host: 38.8.60.5
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete Grant)
- X-Newsreader: Pipeline v3.5.0
-
- On Mar 23, 1996 20:22:54 in article <Newbie Ques: Templates and C++>,
- 'a2patel@novice.uwaterloo.ca (Aashish-Kaski-Ashman-Patel)' wrote:
-
-
- >Ok.. Here is what I am trying to do:
- >1)
- >Have a class called Dictionary that depends on two other classes (
- determined
- >at compile time ).
- >ie. #ifdef HASH
- >class Dictionary Hash-Table;
- >#else-if BST
- >class Dictionary Bst;
- >#endif
- >
- >Now Hashtable is a template class .. defined
- >template <class typeofwhatever>
- >class HashTable
- >{
- >//whatever;
- >}
- >The class definitions are in a header file, and the code in a normal
- source
- >file. The problem is that when I try to compile the source, I get errors.
- >I believe that this is just a syntax probelm.. The error I get is
- >HashTable::HashTable() cannot be defined in the same scope as class
- template.
-
- You didn't show the code, however, from the message it appears your syntax
- is incorrect. It should be something like:
-
- template<class T>
- HashTable<T>::HashTable() {....};
-
- As for the #ifdef's: yes, their syntax is correct.
- --
-
- Pete Grant
- Kalevi, Inc.
- Sofware Engineering
-